package com.redteam.data.beans;

import com.redteam.data.enums.PaymentType;
import java.io.Serializable;

/**
 * Payment bean class used to keep track of all payments in the database
 * @author Teddy Karam
 */
public class Payment implements Serializable {

    private double paymentAmount;
    private PaymentType paymentType;
    private long paymentID;
    private Person person;
    private static final long serialVersionUID = 1L;

    /**
     * Full Payment constructor
     * @param paymentAmount
     * @param paymentType
     * @param paymentID
     * @param personID
     */
    public Payment(double paymentAmount, String paymentType, long paymentID, Person person) {
        this.setPaymentAmount(paymentAmount);
        this.setPaymentType(paymentType);
        this.setPaymentID(paymentID);
        this.setPerson(person);

    }

    /**
     * Default bean constructor
     */
    public Payment() {
    }

    /**
     * Returns the payment amount
     * @return paymentAmount
     */
    public final double getPaymentAmount() {
        return paymentAmount;
    }

    /**
     * Sets the payment amount
     * @param paymentAmount the paymentAmount to set
     */
    public final void setPaymentAmount(double paymentAmount) {
        this.paymentAmount = paymentAmount;
    }

    /**
     * Returns the payment type used
     * @return paymentType
     */
    public final String getPaymentType() {
        return paymentType.getDescription();
    }

    /**
     * Sets the payment type to be used
     * @param paymentType the paymentType to set
     */
    public final void setPaymentType(String paymentType) {
        this.paymentType = PaymentType.valueOf(paymentType);
    }

    /**
     * Returns the payment id of the current payment transaction
     * @return the paymentID
     */
    public final long getPaymentID() {
        return paymentID;
    }

    /**
     * Sets the payment id of the current payment transaction
     * @param paymentID the paymentID to set
     */
    public final void setPaymentID(long paymentID) {
        this.paymentID = paymentID;
    }

    /**
     * Returns the person associated with this payment
     * @return person
     */
    public final Person getPerson() {
        return person;
    }

    /**
     * Sets the person associated with the payment
     * @param person
     */
    public final void setPerson(Person person) {
        this.person = person;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Payment other = (Payment) obj;
        if (Double.doubleToLongBits(this.paymentAmount) != Double.doubleToLongBits(other.paymentAmount)) {
            return false;
        }
        if (this.paymentType != other.paymentType) {
            return false;
        }
        if (this.paymentID != other.paymentID) {
            return false;
        }
        if (this.person != other.person && (this.person == null || !this.person.equals(other.person))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + (int) (Double.doubleToLongBits(this.paymentAmount) ^ (Double.doubleToLongBits(this.paymentAmount) >>> 32));
        hash = 79 * hash + (this.paymentType != null ? this.paymentType.hashCode() : 0);
        hash = 79 * hash + (int) (this.paymentID ^ (this.paymentID >>> 32));
        hash = 79 * hash + (this.person != null ? this.person.hashCode() : 0);
        return hash;
    }
}
